﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/

using System;
using System.Text;
using ISC.MapDotNetServer.Common.Maps;

namespace OI.Framework
{
    public class DensityMapItem
    {
        public bool IsSupported { get; set; }
        public bool IsVisible { get; set; }
        public string ColumnName { get; set; }
        public string Operation { get; set; }


        // parses Layer metadata and return associated item
        public static DensityMapItem ParseDensityMapItem(Layer layer)
        {
            var item = new DensityMapItem();

            if (layer != null && 
                layer.HasDensityMapping())
            {
                string[] dmArray = layer.GetDensityMappingString().Split(',');
                if (dmArray.Length == 3)
                {
                    item.IsSupported = true;
                    item.ColumnName = dmArray[0];
                    item.Operation = dmArray[1];
                    item.IsVisible = Convert.ToBoolean(dmArray[2]);
                }
            }
            return item;
        }


        // serialize filter items
        public static string SerialzeDensityMapItem(DensityMapItem item)
        {
            return item.ColumnName + "," + item.Operation + "," + item.IsVisible;
        }
    }
}
